
#监控键盘事件
import keyboard
import sys
from PIL import ImageGrab,Image
import time

from baiduaip import baiDuAPI
from getText import GetText


def screenShot():
	if keyboard.wait(hotkey='f1') == None:
		print('开始识别')
		if keyboard.wait(hotkey='ctrl+c') == None:
			print('识别结束')
			time.sleep(0.01) # 延迟用于保存图片
			im = ImageGrab.grabclipboard()
			
			if isinstance(im,Image.Image):
				im.save('imageGrab.png')
				print('内容识别成功')
			else:
				print('剪切板里面不是一张图片\n识别失败')
			
			
if __name__ == '__main__':
	# 实例化对象
	baiduapi = baiDuAPI()
	getText = GetText()
	print('文字识别转换')
	
	for _ in range(sys.maxsize):
		screenShot()
		text = baiduapi.picture2Text('imageGrab.png')
		getText.setText(text)
		time.sleep(0.01) # 延迟用于保存图片		
		d = getText.getText()
	
	
	
	